package com.zx.mes.longsecurity.hyl.service.impl;

import com.zx.mes.longsecurity.hyl.dao.UserRepository;
import com.zx.mes.longsecurity.hyl.domain.Tuser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class CustomUserService implements UserDetailsService{

    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        Tuser tuser=userRepository.findByUsername(username);
        if (null==tuser){
            throw new UsernameNotFoundException("用户名不存在");
        }

        return tuser;
    }
}
